﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Base.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    AssessList
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <ext:Viewport ID="ViewPort1" runat="server" Layout="fit">
        <Items>
            <ext:GridPanel ID="GridPanel1" runat="server" Header="false" Border="false" TrackMouseOver="true"
                AutoExpandColumn="assessname" SkipIdForNewRecords="true">
                <Store>
                    <ext:Store ID="dcAssess" runat="server" AutoSave="false" AutoLoad="false">
                        <Proxy>
                            <ext:HttpProxy Url="/Assess/GetAssessStore/" />
                        </Proxy>
                        <UpdateProxy>
                            <ext:HttpWriteProxy Url="/Assess/SaveAssessWithConfirmation/" />
                        </UpdateProxy>
                        <BaseParams>
                            <ext:Parameter Name="userid" Value="_userid" Mode="Raw" />
                            <ext:Parameter Name="createdate" Value="_createdate" Mode="Raw" />
                            <ext:Parameter Name="basetype" Value="_basetype" Mode="Raw" />
                        </BaseParams>
                        <Reader>
                            <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total" MessageProperty="message">
                                <Fields>
                                    <ext:RecordField Name="ID" />
                                    <ext:RecordField Name="userid" />
                                    <ext:RecordField Name="basetype" />
                                    <ext:RecordField Name="assesstype" />
                                    <ext:RecordField Name="assesscount" />
                                    <ext:RecordField Name="assessname" />
                                    <ext:RecordField Name="landarea" />
                                    <ext:RecordField Name="constructionarea" />
                                    <ext:RecordField Name="landprices" />
                                    <ext:RecordField Name="constructionprices" />
                                    <ext:RecordField Name="createdate" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <SortInfo Field="createdate" Direction="DESC" />
                        <Listeners>
                            <Exception Handler="
                                Ext.net.Notification.show({
                                    iconCls   : 'icon-exclamation', 
                                    html      : e && e.message ? e.message : response.message || response.statusText, 
                                    title     : '出错啦', 
                                    hideDelay : 5000
                                });" />
                            <Save Handler="
                                Ext.net.Notification.show({
                                    iconCls   : 'icon-information', 
                                    html      : '保存记录成功', 
                                    title     : '保存成功', 
                                    hideDelay : 5000
                                });" />
                            <Load Handler="dcFineType.load();" />
                        </Listeners>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="ID" DataIndex="ID" Header="ID" Hidden="true">
                            <Editor>
                                <ext:DisplayField ID="DisplayField1" runat="server" StyleSpec="padding-left:5px;font:12px arial, tahoma, helvetica, sans-serif;" />
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="assesstype" DataIndex="assesstype" Header="统计类别" Width="150">
                            <Editor>
                                <ext:SelectBox ID="sltFineType" runat="server" AllowBlank="false" DisplayField="name"
                                    ValueField="name" EmptyText="请选择一个统计类别类别">
                                    <Store>
                                        <ext:Store runat="server" ID="dcFineType" AutoLoad="false">
                                            <Proxy>
                                                <ext:HttpProxy Url="/Assess/GetAssessFineTypeStore/" />
                                            </Proxy>
                                            <BaseParams>
                                                <ext:Parameter Name="basetype" Value="_basetype" Mode="Raw" />
                                            </BaseParams>
                                            <Reader>
                                                <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total" MessageProperty="message">
                                                    <Fields>
                                                        <ext:RecordField Name="id" />
                                                        <ext:RecordField Name="name" />
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <Listeners>
                                        <Select Fn="afterAssessFineTypeSelect" />
                                    </Listeners>
                                </ext:SelectBox>
                            </Editor>
                            <Renderer Handler="if(value == '不参与统计'){
                                                    metadata.style += 'color:#666;';
                                                }
                                                return value ;" />
                        </ext:Column>
                        <ext:Column ColumnID="assessname" DataIndex="assessname" Header="类别" Width="150">
                            <Editor>
                                <ext:TextField ID="TextField1" runat="server" SelectOnFocus="true" AllowBlank="true" >
                                </ext:TextField>
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="assesscount" DataIndex="assesscount" Header="宗数">
                            <Editor>
                                <ext:NumberField ID="NumberField1" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="landarea" DataIndex="landarea" Header="土地面积" Width="80">
                            <Editor>
                                <ext:NumberField ID="NumberField2" runat="server" SelectOnFocus="true" DecimalPrecision="2">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="constructionarea" DataIndex="constructionarea" Header="建筑面积"
                            Width="80">
                            <Editor>
                                <ext:NumberField ID="NumberField3" runat="server" SelectOnFocus="true" DecimalPrecision="2">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="constructionprices" DataIndex="constructionprices" Header="价值（房）"
                            Width="80">
                            <Editor>
                                <ext:NumberField ID="NumberField5" runat="server" SelectOnFocus="true" DecimalPrecision="2">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="landprices" DataIndex="landprices" Header="价值（土）" Width="80">
                            <Editor>
                                <ext:NumberField ID="NumberField4" runat="server" SelectOnFocus="true" DecimalPrecision="2">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                        
                        <ext:CommandColumn Width="25" Hideable="false">
                            <%--<Commands>
                                <ext:GridCommand CommandName="delete" Icon="Cross">
                                    <ToolTip Text="删除" />
                                </ext:GridCommand>
                            </Commands>--%>
                            <%--<PrepareToolbar Handler="toolbar.setVisible(!record.newRecord);" />--%>
                        </ext:CommandColumn>
                    </Columns>
                </ColumnModel>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{dcAssess}.save();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="btnAdd" runat="server" Text="添加" Icon="Add">
                                <Listeners>
                                    <Click Handler="btnSave.disabled = true;btnAdd.disabled = true;_isnewassess=true;#{GridPanel1}.insertRecord(0, { createdate: (new Date()).format('Y-m-d'),basetype:_basetype,assesstype:_lasterassesstype,assesscount:0,assessname:'',landarea:0,constructionarea:0,landprices:0,constructionprices:0,UserID:_userid,ID:''});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.getRowEditor().startEditing(0);" />
                                </Listeners>
                            </ext:Button>
                            <ext:SelectBox ID="sltBaseType" runat="server" AllowBlank="false" DisplayField="Name"
                                ValueField="ID" SelectedIndex="0">
                                <Store>
                                    <ext:Store runat="server" ID="dcBaseType">
                                        <Proxy>
                                            <ext:HttpProxy Url="/Assess/GetAssessBaseTypeStore/" />
                                        </Proxy>
                                        <Reader>
                                            <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total" MessageProperty="message">
                                                <Fields>
                                                    <ext:RecordField Name="ID" />
                                                    <ext:RecordField Name="Name" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                        <Listeners>
                                            <Load Fn="afterAssessBaseTypeLoad" />
                                        </Listeners>
                                    </ext:Store>
                                </Store>
                                <Listeners>
                                    <Select Fn="afterAssessBaseTypeSelect" />
                                </Listeners>
                            </ext:SelectBox>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Plugins>
                    <ext:RowEditor ID="RowEditor" runat="server" ErrorSummary="false" ClicksToEdit="1"
                        CancelText="取消" SaveText="确认">
                        <Listeners>
                            <BeforeEdit Fn="setRowEditorState" />
                            <CancelEdit Fn="rowCancelEdit" />
                            <AfterEdit Fn="AfterRowEdit" />
                        </Listeners>
                    </ext:RowEditor>
                </Plugins>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <Listeners>
                    <Command Fn="commandHandler" />
                </Listeners>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderArea" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="StartupArea" runat="server">
    <script type="text/javascript">
        var _userid = '<%=ViewData("UserID") %>';
        var _createdate = '<%=ViewData("CheckDate") %>';
        var _basetype;
        var _iscommand = false;
        var _isnewassess = false;
        var _lasterassesstype = "";

        var AfterRowEdit = function (el, o, r, rowIndex) {
            if (_isnewassess == true) {
                _lasterassesstype = r.data.assesstype;
                _isnewassess = false;
            }
            btnSave.disabled = false;
            btnAdd.disabled = false;
        }

        var setRowEditorState = function (el, rowIndex) {
            if (_iscommand) {
                btnSave.disabled = true;
                btnAdd.disabled = true;
                _iscommand = false;
                return false;
            }
        }

        var rowCancelEdit = function (el, forced) {
            if (GridPanel1.store.data.items[0].data['assesstype'] == "" | GridPanel1.store.data.items[0].data['assessname'] == "") {
                GridPanel1.store.remove(GridPanel1.store.data.items[0]);
            }
            btnSave.disabled = false;
            btnAdd.disabled = false;
        }

        var afterAssessFineTypeSelect = function (item, record, index) {

        }

        var afterAssessBaseTypeSelect = function (item, record, index) {
            if (typeof (record.data) != 'undefined') {
                if (_basetype != record.data.ID) {
                    _basetype = record.data.ID;
                    dcAssess.load();
                    //dcFineType.load();
                }
            }
        }

        var afterAssessBaseTypeLoad = function (store, records, options) {
            if (records.length > 0) {
                _basetype = records[0].data.ID;
                dcAssess.load();
                //dcFineType.load();
            }
        }

        var commandHandler = function (cmd, record) {
            _iscommand = true;
            switch (cmd) {
                case "delete":
                    Ext.Msg.show({
                        title: '确认',
                        buttons: { yes: '是', no: '否' },
                        msg: '确认删除这项评估吗？',
                        fn: function (btn) {
                            if (btn == "yes") {
                                dcAssess.remove(record);
                                dcAssess.save();
                            }
                        }
                    });
                    break;
            }
        };

        Ext.onReady(function () {

        });
    </script>
</asp:Content>
